#!/usr/bin/python 
#-*- coding=utf-8 -*-

import tornado.web
import tornado.ioloop
import os

class IndexHandler(tornado.web.RequestHandler):
    def initialize(self, root, zk):
        self.root = root
        self.zk = zk

    def get(self):
        topics = self.zk.children('/iotmq/topic')
        topic_list = {}
        for topic in sorted(topics):
            topic_list[topic] = sorted(self.zk.children('/iotmq/topic/' + topic))
        meta_data = {
            'zk': self.zk,
            'master': sorted(self.zk.children('/iotmq/master')),
            'backup-master': sorted(self.zk.children('/iotmq/backup-master')),
            'ds-group': self.zk.children('/iotmq/ds-group'),
            'topic': topic_list,
            'client': self.zk.children('/iotmq/client')
        }
        self.render(os.path.join(self.root + '/template/index.html'), meta = meta_data)

    def post(self):
        self.write('unsupport method')
